{use master_page('admin/v_master')} 

{block content}
<?php 
$cu_group = $this->usergroup_manager->get($this->current_user()->usergroup_id);  
?>

<?php $ci = &get_instance(); 
function bl_class($children,$level=1)
{
	$ci = & get_instance();
	foreach($children as $child)
	{
		$title = $child->title;
		$pad = "";
		if($level>1)
		{
			for($i=0;$i<$level-1;$i++)
			{
				$pad = $pad . "&nbsp;&nbsp;";
			}
			$pad = $pad."└";
		}
		if($level == 1){
			$pad="";
		}
		// $title = str_pad($title,'-',strlen($title)+level,STR_PAD_LEFT);

		echo "<option value='".$child->id."'>$pad$title</option>" ;
		if(sizeof($child->children)>0)
		{
			bl_class($child->children,$level+1);
		}
	}
}
?>


<script>
$(document).ready(function(){
	$('#type').change(function(){
		var v = $(this).val(); 
		<?
		$get_type = array_remove($_GET, 'type');
		$get_params = Array();
		foreach($_GET as $k=>$v)
		{
			$get_params[] = "$k=$v";
		}
		$get_params_str = implode('&',$get_params);
		?>
		var url = '<?=_U("link/index?")?><?=$get_params_str?>&type=' + v;
		//alert(url);
		//window.open(url);
		window.location.href = url ;  
	}) ;

	$("#chkall").click(function(){
		var checked = $(this).attr("checked");
		$(".datatable tbody input[type=checkbox]").attr("checked",checked) ;  
	}) ; 
	
})
</script>
<div style="margin-bottom:0px;height:">
<div class="blank20" style="height:10px;"></div>
<form id = 'form1' action = '<?=$_SERVER['REQUEST_URI']?>' method='post'>
	<?php if($cu_group->permission("link","edit")):?>
	<div style="padding-left:10px;">
		<input style="width:132px;height:38px;line-height:38px;color:white;background:url(images/btn_03.gif) left top no-repeat;border:none; text-align:center;
 			 cursor: pointer;" class="btn_c" type="button" value=" 添加链接 " 
 			 onclick="javascript:window.location.href='<?php echo _U("link/edit?tab=link_manager&class_id=").$this->input->get('class-id')?>'">
	</div>
	<?php endif;?>
	<div class="blank5" style="height:10px;"></div>
	<div id="tagscontent" class="right_box">
		<table class="datatable" >
			<thead>
				<tr class="top_page" style="height:40px">
					<td colspan='7' style="padding:5px 9px;text-align:center;height:40px">
						<? $this->load->view('admin/v_pager',$sp_config); ?>
					</td>
				</tr>
				<tr>
					<th>
						<input title="点击可全选本页的所有项目" type="checkbox" id="chkall">
					</th> 
					<th width="100px">类别<?=lang('link_class')?></th>
					<th><!--catid-->ID</th>
					<th><!--catname-->栏目名称</th>
					<th><!--htmldir-->URL</th>
					<th><!--isnav-->操作</th>
				</tr>
			</thead>
			<tbody>
			<?php foreach($links as $link):?>
			<tr>
				<td style="width:31px;">
					<input type="checkbox" value="<?php echo $link->id;?>"  name="ids[]">
				</td>
				<td align="center">{link->class->title}</td>
				<td >{link->id}</td>
				<td >
					<a onmouseover="tooltip.show('点击进入链接');" onmouseout="tooltip.hide();
						" href="<?=("$link->url")?>" target="_blank">{link->title}</a>
				</td>
				<td >{link->url}</td>
				<td >
					<?php if($cu_group->permission("link","edit")):?>
					<a class="edit" onmouseover="tooltip.show('编辑');" onmouseout="tooltip.hide();"
						href="<?=_U('link/edit?tab=link_manager&id='.$link->id)?>&class_id=<?=!empty($_GET['class-id'])?$this->input->get('class-id'):$link->class_id;?>"></a>
					<?php endif;?> 
					<?php if($cu_group->permission("link","del")):?>
					<a class="delete" onmouseover="tooltip.show('删除');" onmouseout="tooltip.hide();" onclick="javascript:return confirm('确认删除');" 
						href="<?=_U('link/del/'.$link->id)?>"></a>
					<?php endif;?> 
				</td>
			</tr>
			<?php endforeach;?>
			<tr>
				<td colspan='7' style="padding:5px 9px;text-align:center;height:40px">
					<? $this->load->view('admin/v_pager',$sp_config); ?>
				</td>
			</tr>
			
		</table>
	</div>
<script>
$(document).ready(function(){
	$('#btn_delete').click(function(){
		var frm = $("#form1");
		frm.attr('action','<?php echo _U("link/del");?>'); 
		frm.submit();
	});
	$('#btn_moveto').click(function(){
		var frm = $("#form1");
		var id = $("#class_id").val();
		if(id!="")
		{
			var url = '<?php echo _U("link/moveto/");?>' + id;
			frm.attr('action',url); 
			frm.submit();
		}
		else
		{
			alert("请选择移动到的分类") ;      
		}
	});
});
</script>
	<div class="blank10" style="height:10px"></div>
	<input type="hidden" name="batch" value="">
	<?php if($cu_group->permission("link","del")):?>
	<input class="btn_d" type="button" value=" 删除 " id="btn_delete">
	<?php endif;?> 
	<?php if($cu_group->permission("link","moveto")):?>
	<input class="btn_e" type="button" value=" 移动到 " id="btn_moveto" >
	<?$children = $this->link_class_manager->get_root_list();?>
	<select id = 'class_id' class='bind'>
		<option value="">请选择</option>
		<?php bl_class($children,1)?>
	</select>
	<?php endif;?> 
	
</form>
</div>
{end}